package com.geoboard.service;

import java.util.ArrayList;

import android.util.Log;
import android.util.SparseArray;

import com.android.volley.Response;
import com.geoboard.entity.Board;
import com.geoboard.fragments.MapFrag;

public class GetBoardsListener implements Response.Listener<ArrayList<Board>>{

	/**** Members **************************************************/
	private MapFrag mMapFrag;
	private SparseArray<ArrayList<Board>> mRevealedBoards;
	private String TAG = this.getClass().getSimpleName();
	
	//TODO thread safe?
	public GetBoardsListener (MapFrag mapFrag) {
		mMapFrag = mapFrag;
		mRevealedBoards = mMapFrag.getRevealedBoards();
	}
	
	@Override
	public void onResponse(ArrayList<Board> boards) {
		Log.d(TAG, String.format("Recieved %d boards", boards.size()));
		for (Board board : boards) {
			if (!mRevealedBoards.get(board.getZoom()).contains(board)) //don't add duplicates
				mRevealedBoards.get(board.getZoom()).add(board);
		}
		mMapFrag.displayBoards();
	}
}
